package com.sanjiahantang.youjiaclient.module.decorate.views.impl;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpFragment;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.module.login.views.impl.LoginActivity;
import com.sanjiahantang.youjiaclient.module.decorate.presenters.DecorateManagePresenter;
import com.sanjiahantang.youjiaclient.module.decorate.views.DecorateManageView;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;


/**
 * Created by zy on 2017/9/14.
 */

public class DecorateManageFragment extends BaseMvpFragment<DecorateManageView,DecorateManagePresenter> implements DecorateManageView, View.OnClickListener {

    private TextView txtTitle;
    private View back,$view;
    private MagicIndicator miTabs;

    @Override
    public void showProgress() {
        context.showProgress(context);
    }

    @Override
    public void hideProgress() {
        if (context != null) context.hideProgress();
    }

    @Override
    public DecorateManagePresenter initPresenter() {
        return new DecorateManagePresenter();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if ($view != null) {
            ViewGroup parent = (ViewGroup) $view.getParent();
            if (parent != null) {
                parent.removeView($view);
            }
        } else {
            $view = inflater.inflate(R.layout.fragment_decorate_manage, container, false);
        }
        return $view;
    }

    @Override
    public void initView() {
        txtTitle = (TextView) $view.findViewById(R.id.title);
        back =  $view.findViewById(R.id.fl_Left);
        miTabs = (MagicIndicator) $view.findViewById(R.id.miTabs);
        txtTitle.setText("装修管理");
        back.setOnClickListener(this);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

            switch (requestCode){
                case KEY_DECORATE:
//                    if (!TextUtils.isEmpty(ConfigValue.DATA_KEY)){
//                        presenter.setFragmentManager(getChildFragmentManager());
//
//                        presenter.loadTab(context,new BindTabListener(){
//
//                            @Override
//                            public void bindAdapter(CommonNavigatorAdapter adapter) {
//                                final CommonNavigator commonNavigator = new CommonNavigator(context);
//                                commonNavigator.setAdapter(adapter);
//                                miTabs.setNavigator(commonNavigator);
//                            }
//
//                            @Override
//                            public void switchPages(int index) {
//                                miTabs.onPageSelected(index);
//                            }
//
//                            @Override
//                            public void reload() {
//                                initData();
//                            }
//                        });
//                    }
//                    break;

        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if(TextUtils.isEmpty(ConfigValue.DATA_KEY)){
            Intent intent=new Intent(context, LoginActivity.class);
            startActivityForResult(intent,KEY_DECORATE);
        }else {
            presenter.setFragmentManager(getChildFragmentManager());

//            presenter.loadTab(context,new BindTabListener(){
//
//                @Override
//                public void bindAdapter(CommonNavigatorAdapter adapter) {
//                    final CommonNavigator commonNavigator = new CommonNavigator(context);
//                    commonNavigator.setAdapter(adapter);
//                    miTabs.setNavigator(commonNavigator);
//                }
//
//                @Override
//                public void switchPages(int index) {
//                    miTabs.onPageSelected(index);
//                }
//
//                @Override
//                public void reload() {
//                    initData();
//                }
//            });
        }
    }

    @Override
    public void initData() {



    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fl_Left:
                context.finish();
                break;
        }
    }


    @Override
    public DecorateManagePresenter getPresenter() {
        return presenter;
    }


}
